import React, { Component } from 'react'
import { View, Text,Button } from '@tarojs/components'
import { connect } from 'react-redux'
import './index.less'

function mapStateToProps(state) {
  return { thread: state.thread }
 }
  const mapDispatchToProps = dispatch => {
     return {
       changeApp: data => dispatch({ type: 'USER', data })
     }
   }
@connect(({user})=>({user}),mapDispatchToProps)

 class User extends Component {
  state= {
    name:'sjy'
  }
  componentWillMount () { }

  componentDidMount () { }

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }
  change() {
    console.log(this.state.name);
    this.props.changeApp({userName:'哟哟哟'})
  }
  render () {
    return (
      <View className='index'>
        <Text>我是 user!{this.props.user.userName}</Text>
        <Button onClick={()=>{this.change()}}>触发app的action</Button>
      </View>
    )
  }
}

export default User
